// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

import { tool } from '../tool/UITool';
import { PrefabKey } from '../define/PrefabKey';

const { ccclass, property } = cc._decorator;

@ccclass
export default class HintView extends cc.Component {
  // LIFE-CYCLE CALLBACKS:

  // onLoad () {}

  @property(cc.Prefab)
  HintLabel: cc.Prefab = null;

  start() {}

  public showSingleHint(data): void {
    let text: string = data.txt;
    let hintTxt: cc.Node = tool.getPrefab(PrefabKey.Hint_Label, this.HintLabel);
    this.node.addChild(hintTxt);

    hintTxt.scale = 0;
    hintTxt.x = 0;
    hintTxt.y = 50;
    cc.find('txt', hintTxt).getComponent(cc.RichText).string = '<color=#FFFFFF>' + text + '</c>';
    let action = cc.sequence(
      cc.scaleTo(0.2, 1),
      cc.moveBy(0.2, 0, 60),
      cc.moveBy(0.8, 0, 20),
      cc.callFunc(() => {
        hintTxt.removeFromParent();
        tool.pushPrefab('hint', hintTxt);
      }),
    );
    hintTxt.runAction(action);
  }

  // update (dt) {}
}
